<template>
	<div>
		<div class="layout-breadcrumb">
			<Breadcrumb>
			    <BreadcrumbItem href="/">首页</BreadcrumbItem>
			    <BreadcrumbItem href="/configs/">系统配置</BreadcrumbItem>
			    <BreadcrumbItem href="/configs/smstpl">短信模版管理</BreadcrumbItem>
			</Breadcrumb>
		</div>
		<div class="layout-content">
		    <div class="layout-content-main">
		    	<Tabs value="tpl" @on-click="changeTab">
			        <TabPane label="短信模版" name="tpl">
			        	<Tpl ref="tpl"></Tpl>
			        </TabPane>
			        <TabPane label="测试" name="test">
			        	<Test ref="test"></Test>
			        </TabPane>
			    </Tabs>
		    	
		    </div>
		</div>
	</div>
</template>
<script>
	import Button from 'iview/src/components/button';
	import Breadcrumb from 'iview/src/components/breadcrumb';
	import Tabs from 'iview/src/components/tabs';

	import Tpl from 'admin/components/configs/smstpl/tpl';
	import Test from 'admin/components/configs/smstpl/test';
	import Axios from 'admin/config/axios';

	export default{
		components:{
            Breadcrumb,
            'BreadcrumbItem' : Breadcrumb.Item,
            Tabs,
            'TabPane' : Tabs.Pane,
            Tpl,
            Test,
        },
        data () {
            return {
            	
            }
        },
        methods:{
        	//测试标签页获取所有模版
        	testTab(){
        		var config_ids = this.$refs['tpl'].config_ids;
        		var modules = this.$refs['tpl'].modules;
        		this.$refs['test'].formReset();
        		//获取所有模版,并获取服务商和模块名
        		Axios.Configs.SmsTpl.All()
	            .then(res=>{
	                var data = res.data;
	                this.$refs['test'].smstpls = [];
	                var tranData = [];
	                //生成服务商短信数组结构
	                for(var i in data){
	                	var config_id = data[i]['config_id'];
	                	var module = data[i]['module'];
	                	for(var c in config_ids){
	                		if(config_ids[c]['id']==config_id){
	                			tranData[config_ids[c]['vue']] = {'id' : config_ids[c]['id'], 'name':config_ids[c]['desc'],'child': new Array()};
	                			break;
	                		}
	                	}
	                	
	                }
	                //服务商短信模版数据赋值
	                for(var i in data){
	                	var config_id = data[i]['config_id'];
	                	var module = data[i]['module'];
	                	for(var c in config_ids){
	                		if(config_ids[c]['id']==config_id){
	                			break;
	                		}
	                	}
	                	for(var m in modules){
	                		if(modules[m]['value']==module){
	                			data[i]['module_name'] = modules[m]['name'];break;
	                		}
	                	}
	                	tranData[config_ids[c]['vue']]['child'].push(data[i]);
	                }
	                for(var i in tranData){
	                	this.$refs['test'].smstpls.push(tranData[i]);
	                }
	           
	                // this.$refs['test'].smstpls = tranData;
	                // console.log(this.$refs['test'].smstpls);
	                // console.log(this.$refs['test'].smstpls);

	            })
        	},
        	changeTab(name){
        		if(name=='test'){
        			this.testTab();
        		}
        	}
        },
        created:function(){
        }
	}
</script>